8990. Vowels doubling

 

A string consists of lowercase Latin letters and spaces. Double all vowels in it, that is, the letters aeiou and y.

 

Input. One line, consisting of lowercase Latin letters and spaces. The line contains no more than 1000 symbols.

 

Output. Print a string with all doubled vowel letters.

 

Sampe input

Sampe output

welcome to python

weelcoomee too pyythoon

 

 

SOLUTION

strings

 

Algorithm analysis

Declare a pointer i to the start of the original char array s and a pointer j to the start of the resulting char array t: i = j = 0. Move the pointer i through the letters of the string. For each letter of the string s that is not a vowel, copy s[i] to t[j] and move j one position forward. If the letter s[i] is a vowel, then put it twice at the end of the string t.

 

Algorithm realization

Declare the input char array s and the resulting t.

 

char s[1001], t[2001];

 

Read the input string.

 

gets(s);

 

Copy the letter s[i] into t[j] and increase the index j by 1. If s[i] is a vowel, then put s[i] at the end of array t twice.

 

int j = 0;

for (int i = 0; i < strlen(s); i++)

  if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||

      s[i] == 'u' || s[i] == 'y')

  {

    t[j++] = s[i];

    t[j++] = s[i];

  }

  else

    t[j++] = s[i];

 

At the end of the resulting string put a zero byte.

 

t[j] = 0;

 

Print the answer.

 

puts(t);

 

Algorithm realizationC++

Read the input string.

 

getline(cin, s);

 

Initialize the resulting string res.

 

res = "";

 

Iterate over the characters of a string.

      If s[i] is a vowel, then add two letters of s[i] to res.

      If s[i] is a consonant, then add one letter of s[i] to res.

 

for (i = 0; i < s.size(); i++)

{

 

Add the letter s[i] to res.

 

  res = res + s[i];

 

If s[i] is a vowel, add the letter s[i] to res.

 

  if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||

      s[i] == 'u' || s[i] == 'y')

    res = res + s[i];

}

 

Print the answer.

 

cout << res;

 

Java realization

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    String s = con.nextLine();

    String res = "";

    for(int i = 0; i < s.length(); i++)

      if (s.charAt(i) == 'a' || s.charAt(i) == 'e' ||

          s.charAt(i) == 'i' || s.charAt(i) == 'o' ||

          s.charAt(i) == 'u' || s.charAt(i) == 'y' )

        res = res + s.charAt(i) + s.charAt(i);

      else

        res = res + s.charAt(i);

    System.out.println(res);

    con.close();

  }

}

 

Python realization

Read the input string.

 

s = input()

 

Initialize the resulting string res.

 

res = ""

 

Iterate over the characters of a string.

·        If s[i] is a vowel, then add two letters of s[i] to res.

·        If s[i] is a consonant, then add one letter of s[i] to res.

 

for ch in s:

 

Add the letter ch to res.

 

  res += ch

 

If ch is a vowel, add the letter ch to res.

 

  if ch in "aeiouy":

    res += ch

 

Print the answer.

 

print(res)